#include "cReportTargetHTML.h"

cReportTargetHTML::cReportTargetHTML(void)
{
	MemBuffer.clear();
	MemBuffer += "<html>\n";
	MemBuffer += "<body>\n";


}

cReportTargetHTML::~cReportTargetHTML(void)
{
}


int cReportTargetHTML::Initialize(void)
{
	return 0;
}

int cReportTargetHTML::AddNewPage(void)
{
	return 0;
}

int cReportTargetHTML::DrawLine(int x1,int y1, int x2,int y2)
{
	return 0;
}

int cReportTargetHTML::DrawText(const cText* Text)
{
	char* buffer = new char[512];
	string temp;
	string style;
	
	// position 
	style += "position:fixed; ";
	sprintf(buffer,"top: %dmm; ",Text->GetY());
	style += buffer;
	sprintf(buffer,"left: %dmm; ",Text->GetX());
	style += buffer;

	// Width
	sprintf(buffer,"Width: %dmm; ",Text->GetWidth());
	style += buffer;
	
	// Height
	if(Text->HeightIsSetted() == true)
	{
		sprintf(buffer,"Height: %dmm; ",Text->GetHeight());
		style += buffer;
	}
	// size
	if(Text->WidthIsSetted() == true)
	{
		sprintf(buffer,"font-size: %dmm; ",Text->GetSize());
		style += buffer;
	}
	// Horizontal Align
	switch(Text->GetHorizontalAlign())
	{
	default:
	case eHorizontalAlign::left :
		style += "text-align: left; ";	
		break;
	case eHorizontalAlign::center :
		style += "text-align: center; ";	
		break;
	case eHorizontalAlign::right :
		style += "text-align: right; ";	
		break;
	case eHorizontalAlign::justify :
		style += "text-align: justify; ";	
		break;
	}
	// color
	if(Text->GetColor()!=NULL)
	{
		style += string("color:#") + Text->GetColor() + "; ";
	
	}

	temp += "<p style=\"" + style + "\">";
	temp += Text->GetText();
	temp += "</p>\n";
	MemBuffer += temp;
	


	
	delete buffer;
	return 0;
}

int cReportTargetHTML::DrawBox(int x1,int y1, int x2,int y2)
{
	char* buffer = new char[512];
	string temp;
	string style;
	
	// position 
	style += "position:fixed;";
	sprintf(buffer,"top: %dpx;",y1);
	style += buffer;
	sprintf(buffer,"left: %dpx;",x1);
	style += buffer;

	sprintf(buffer,"height: %dpx;",y2-y1);
	style += buffer;
	sprintf(buffer,"width: %dpx;",x2-x1);
	style += buffer;
	style += "border: 3px;";
	style += "border-style: solid;";
	style += "border-color: #ff0000;";

	temp += "<div style=\"" + style + "\">";
	temp += "</div>\n";
	MemBuffer += temp;
	


	
	delete buffer;
	return 0;
}

int cReportTargetHTML::Save(const char* FileName)
{
	FILE* fp = NULL;
	fopen_s(&fp, FileName,"w");

	fwrite(MemBuffer.c_str(),1,MemBuffer.size(),fp);
	
	return 0;
}

int cReportTargetHTML::Close(void)
{
	MemBuffer += "</body>\n";
	MemBuffer += "</html>\n";
	return 0;
}
